package com.chaosj.skill.prometheus

import io.micrometer.core.instrument.Gauge
import io.micrometer.core.instrument.Metrics
import io.micrometer.core.instrument.simple.SimpleMeterRegistry

import java.util.concurrent.atomic.AtomicInteger

/**
 * @Description:
 * @author caoyangjie
 * @date 2020年01月2020/1/14日 14:03
 * @Copyright: © 赢时胜
 */
class GaugeSample {
    static void main(args){
        AtomicInteger atomicInteger = new AtomicInteger()
        Gauge gauge = Gauge.builder("gauge", atomicInteger, {v->Double.valueOf(atomicInteger.get())})
                .tag("gauge", "gauge")
                .description("gauge")
                .register(new SimpleMeterRegistry())
        atomicInteger.addAndGet(5)
        System.out.println(gauge.value())
        System.out.println(gauge.measure())
        atomicInteger.decrementAndGet()
        System.out.println(gauge.value())
        System.out.println(gauge.measure())
        //全局静态方法，返回值竟然是依赖值，有点奇怪，暂时不选用
    }
}
